import java.io.*;
import java.net.*;
import java.util.*;
import java.security.Security;
import java.security.Provider;
import javax.net.ssl.*;
import local.util.MyPrint;
import java.text.DecimalFormat;

import local.util.MyStringFormat;
import local.util.MyPrint;

public class VectorCheck {

    Vector recordVector = new Vector ();

    public static void main (String args[]) {

	System.out.println("Input: URL returned Vector");
	System.out.println("Print out record head");
	System.out.println("Print out number of columns");
	System.out.println("Print out unmatch elements!");
    }

    public int getTableColumnSize(Vector input_v) {

	int length[] = {0, 0, 0};
	int number_column = 0;
	Object temp_o, temp_o1;
	String tick, tick1;  
	Hashtable tick_hashtab = new Hashtable();

	Vector record_v_v = new Vector ();
	Vector record_head_vector = new Vector ();

	DataBaseQuery db = new DataBaseQuery ();
	String db_qr_str = null;

	db_qr_str = "SELECT * FROM tick";

	db.setTickTableHashtable(db_qr_str, "Tick","Sector_Id");
	tick_hashtab = db.getTickTableHashtable();

	Enumeration enum = input_v.elements();
	int m = 0;   
	while ( enum.hasMoreElements()) {
	 
	    temp_o = enum.nextElement();
	    
	    tick = (String)temp_o;
	  
	    if (tick_hashtab.containsKey(tick)){
		length[m] = input_v.indexOf(tick);
		m++;
		if (m > 2) {
		    if((length[1]-length[0]) ==  (length[2]-length[1])) {
			number_column = length[1]-length[0];
			System.out.println("number of column is:"+number_column);
			break;
		    }
		    else {
			m = 0;
		    }
		}
		else {
		    continue;
		}
	    }
	}

	Enumeration enum2 = input_v.elements();

	for (int j=0; j< number_column; j++) {
	 
	    record_head_vector.add( (String)enum2.nextElement() );
	}

	return number_column;
    }

    public void checkUrlReturnVector( Vector input_v) {
  
	int length[] = {0, 0, 0};
	int number_column = 0;
	Object temp_o, temp_o1;
	String tick, tick1;  
	Hashtable tick_hashtab = new Hashtable();

	Vector record_v_v = new Vector ();
	Vector record_head_vector = new Vector ();

	DataBaseQuery my_query = new DataBaseQuery ();

	my_query.setTickTableHashtable ("SELECT * FROM Tick", "Tick", "Tick");
	tick_hashtab =  my_query.getTickTableHashtable();

	number_column = getTableColumnSize(input_v);
	
	int index = 0;
	int next_index = 0;
	Enumeration enum1 = input_v.elements();
	int mm =0 ;
	while ( enum1.hasMoreElements()) {

	    for (; mm<number_column; mm++) {
		System.out.println("Table Head Element: "+ enum1.nextElement());
	    }

	    temp_o1 = enum1.nextElement();
	    tick1 = (String)temp_o1;
	 
	    if (tick_hashtab.containsKey(tick1)) {
		index = input_v.indexOf(tick1);
		next_index = index + number_column;
 
		if (next_index < input_v.size()) {

		    System.out.println("Elements of "+tick1 +" Found=========");

		    if (tick_hashtab.containsKey((String)input_v.elementAt(next_index))){

			System.out.println("Checking number of elements of "+tick1 +"  OK");
			Vector record_v   = new Vector ();
			record_v.addElement(tick1);
			for (int j =1; j <number_column; j++) {
			    record_v.addElement((String)enum1.nextElement());
			}

			record_v_v.addElement(record_v);
		    }
		    else {
			System.out.print("Can not find(2) "+input_v.elementAt(next_index));
			System.out.println("  In Tick File or ");
			System.out.println("Number of elements of "+tick1 +"#### Not Ok Not OK ######");
			
			continue;
		    }
		}
		else if (next_index == input_v.size()){
		
		    Vector record_v   = new Vector ();
		    record_v.addElement(tick1);

		    for (int j =1; j <number_column; j++) {
			record_v.addElement((String)enum1.nextElement());
		    }
		    System.out.println("End of Vector Check");
		    record_v_v.addElement(record_v);
		}
	    }
	    else {
		System.out.println(tick1);
		continue;
	    }
	}

	setRecordVector(record_v_v);
    }

    public void setRecordVector (Vector rv) {

	recordVector = rv;
    }

    public Vector getRecordVector () {

	return recordVector;
    }
}
